<template>
	<view class="mask" v-if="show">
		<view class="content">
			<view class="title">
				<text class="text">{{title}}</text>
			</view>
			<view class="body">
				<slot></slot>
			</view>
			<view class="footer">
				<view class="item cancle" @tap="close">
					<text class="text">取消</text>
				</view>
				<view class="item confirm" @tap="confirm">
					<text class="text">确定</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script setup>
	import { ref } from 'vue';
	const props = defineProps({
		title: {
			type: String,
			default: ''
		}
	})
	const emit = defineEmits(['confirm'])
	
	const show = ref(false) // 控制弹窗的显示
	
	const close = () => { // 关闭弹窗
		show.value = false
	}
	
	const open = () => { // 打开弹窗
		show.value = true
	}
	
	const confirm = () => { // 点击确定
		emit('confirm')
	}
	
	defineExpose({ // 向父组件暴露
		show,
		confirm,
		open,
		close
	})
	
</script>

<style lang="less" scoped>
	.mask {
		display: flex;
		flex-direction: row;
		justify-content: center;
		position: fixed;
		top: 0;
		right: 0;
		bottom: 0;
		left: 0;
		background-color: rgba(0, 0, 0, .3);

		.content {
			width: 500rpx;
			// height: 300rpx;
			position: absolute;
			top: 350rpx;
			border-radius: 20rpx;
			background-color: #fff;
			.title{
				height: 50rpx;
				display: flex;
				flex-direction: row;
				justify-content: center;
				align-items: center;
				.text{
					font-size: 30rpx;
				}
			}
			.body{
				padding: 50rpx 20rpx;
			}
			.footer{
				height: 80rpx;
				display: flex;
				flex-direction: row;
				align-items: center;
				.item{
					flex: 1;
					display: flex;
					flex-direction: row;
					align-items: center;
					justify-content: center;
					.text{
						font-size: 30rpx;
					}
				}
				.confirm{
					height: 80rpx;
					border-radius: 0 0 20rpx 0;
					background-color: #f7931e;
				}
			}
		}
	}
</style>